import React, { Component } from 'react'
import { Switch, Route, Redirect } from 'react-router-dom'

export default class Index extends Component {
    render() {
        /* eslint-disable */
        const { routes } = this.props
         /* eslint-disable */
        const normalRoutes = routes.filter((item) => !item.to)
         /* eslint-disable */
        const redirectRoutes = routes.filter((item) => item.from).map((item, key) => <Redirect key={key} from={item.from} to={item.to} />)
        return (
            <Switch>
                {
                    normalRoutes && normalRoutes.map((item, key) => (
                        <Route
                            key={key}
                            path={item.path}
                            render={(props) => <item.component {...props} routes={item.children} />}
                        />
                    )).concat(redirectRoutes)
                }
            </Switch>
        )
    }
}
